home *** CD-ROM | disk | FTP | other *** search
Wrap
BEGIN { #{{{}}} # {{{ normal replacements max_command=32 BASENAME="name.sed" TMPNAME="/tmp/"BASENAME".tmp." # }}} # {{{ paths rc = "" help = "" msg = "" bold = "\\fB" ital = "\\fI" norm = "\\fP" file_limit = ",\n.br\n" contents = ".br\n%s -\n.br\n files containing the %s\n" base = "origami" nrc = 0 # }}} } #{{{ path strings /^(ORIGAMI_RC|KBD)_PATH_STRING / { replace[$1]=$2 next } /^ORI_RC_PATH_MANTEXT / { for (i=1;i<length($2);i++) { # {{{ maybe add limiter if (nrc>0) { rc = rc file_limit help = help file_limit msg = msg file_limit } # }}} nrc = nrc + 1 # {{{ add font switch to bold rc = rc bold help = help bold msg = msg bold # }}} # {{{ append-path-name while ((i<=length($2)) && (substr($2,i,1)!=":")) { rc = rc substr($2,i,1) help = help substr($2,i,1) msg = msg substr($2,i,1) i = i+1 } # }}} # {{{ add font-switches, includeing rc,.. rc = rc "/." norm ital base norm bold "rc" norm help = help "/." norm ital base norm bold "help" norm msg = msg "/." norm ital base norm bold "msg" norm # }}} } next } #}}} #{{{ simple replace-defines $1~/^[KO]_/ && $3~/^COM[_ICAP]*$/ && $4!="NONE" { replace[$1]=$4 next } substr($1,1,1)!="#" && $3=="OPP-KEY" { replace[$1]=$2 next } substr($1,1,1)!="#" && $3=="OCL-KEY" { replace[$1]=$2 next } $1=="#define" { replace[$2]=substr($3,2,length($3)-2) next } #}}} { next } END { replace["ORI_RC_PATH_MANTEXT"]=".SH FILES\n"sprintf(contents,rc,"bindings and macros")sprintf(contents,help,"help")sprintf(contents,msg,"print formats")sprintf(".PP\n%s\n",ital base norm " can be replaced with command line option (" bold "\-k" norm ") or name of the executable.") # {{{ print header of shell script for calling sed printf("#! /bin/sh\n") >BASENAME print("#") >BASENAME print("# script generated automatically, using sed-cmd-file "TMPNAME"[s01]") >BASENAME print("#") >BASENAME print("") >BASENAME printf("trap %c/bin/rm -f "TMPNAME"?%c 0 1 2 3 15\n",34,34) >BASENAME print("") >BASENAME # }}} destfile=TMPNAME"1" sourcefile="" mod=0 sedname=TMPNAME"s" lastout=destfile # {{{ print all replace statements # {{{ print language replace statement print("#{{{ sed-run `language tbl' ..") >BASENAME print("cat lg.sed >"sedname) >BASENAME print("cat >>"sedname" <<\\HERE") >BASENAME n=max_command*3/4 # }}} for ( s in replace ) { # {{{ maybe switch command file if (++n>max_command) { print("HERE") >BASENAME print("sed -f "sedname" "sourcefile" >"destfile) >BASENAME print("#}}}") >BASENAME print("#{{{ sed-run `"s"' ..") >BASENAME print("cat >"sedname" <<\\HERE") >BASENAME n=0 sourcefile="<"destfile destfile=TMPNAME mod mod=1-mod lastout=destfile } # }}} # {{{ get replacement string, handle some chars in a special way for (do_replace="";replace[s]!="";) { # {{{ .SH -> .SH if (substr(replace[s],1,3)==".SH") { do_replace=do_replace ".SH" replace[s]=substr(replace[s],4) continue } # }}} # {{{ .br -> .br if (substr(replace[s],1,3)==".br") { do_replace=do_replace ".br" replace[s]=substr(replace[s],4) continue } # }}} # {{{ \f([BIP]) -> \\f\1 if (substr(replace[s],1,3)=="\\fB" || substr(replace[s],1,3)=="\\fI" || substr(replace[s],1,3)=="\\fP" ) { do_replace=do_replace "\\" substr(replace[s],1,3) replace[s]=substr(replace[s],4) continue } # }}} # {{{ \n -> \ and \n if (substr(replace[s],1,1)=="\n") { do_replace=do_replace "\\\n" replace[s]=substr(replace[s],2) continue } # }}} # {{{ \\ -> \ \ e if (substr(replace[s],1,2)=="\\\\") { do_replace=do_replace "\\\\e" replace[s]=substr(replace[s],3) continue } # }}} # {{{ \ -> \ \ e if (substr(replace[s],1,1)=="\\") { do_replace=do_replace "\\\\e" replace[s]=substr(replace[s],2) continue } # }}} # {{{ & -> \ & if (substr(replace[s],1,1)=="&") { do_replace=do_replace "\\&" replace[s]=substr(replace[s],2) continue } # }}} # {{{ / -> \ / if (substr(replace[s],1,1)=="/") { do_replace=do_replace "\\/" replace[s]=substr(replace[s],2) continue } # }}} # {{{ . -> \ & . if (substr(replace[s],1,1)==".") { do_replace=do_replace "\\\\\\&." replace[s]=substr(replace[s],2) continue } # }}} # {{{ copy the original do_replace=do_replace substr(replace[s],1,1) replace[s]=substr(replace[s],2) # }}} } # }}} print("s/>>>"s"<<</"do_replace"/g") >BASENAME } print("HERE") >BASENAME print("sed -f "sedname" "sourcefile" >"destfile) >BASENAME print("#}}}") >BASENAME # }}} print("") >BASENAME print("cat "lastout) >BASENAME }